package com.leo;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.ComboBox;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;

/**
 * @ClassName ComboBoxDemo
 * @Description
 * @Author wangss
 * @date 2020.05.25 11:45
 * @Version 1.0
 */
public class ComboBoxDemo extends Application {

    public static void main(String[] args) {
        launch(args);
    }

    @Override
    public void start(Stage primaryStage) throws Exception {
        AnchorPane anchorPane = new AnchorPane();
        anchorPane.setStyle("-fx-background-color: #e7eeea");
        Scene scene = new Scene(anchorPane);

        Button button = new Button("点击");

        ComboBox<String> comboBox = new ComboBox<>();
        comboBox.getItems().addAll("item1", "item2", "item3", "item4", "item5");

        // 可以编辑
        comboBox.setEditable(true);
        // 文本提示
        comboBox.setPromptText("请输入内容");
        // 占位符，里边没有元素的时候起作用
//        comboBox.setPlaceholder(new Button("我是占位按钮"));

        // 设置默认显示多少行
        comboBox.setVisibleRowCount(3);

        AnchorPane.setTopAnchor(comboBox, 10d);
        AnchorPane.setLeftAnchor(comboBox, 10d);
        AnchorPane.setTopAnchor(button, 10d);
        AnchorPane.setLeftAnchor(button, 260d);
        anchorPane.getChildren().addAll(comboBox, button);

        primaryStage.setScene(scene);
        primaryStage.setTitle("combobox");
        primaryStage.setWidth(625d);
        primaryStage.setHeight(500d);
        primaryStage.setResizable(false);
        primaryStage.show();

        comboBox.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> {

        });
    }
}
